package top.infopub.mgr.mkt.web;

import com.github.pagehelper.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import top.infopub.enums.mkt.ProProcessDetailTypeEnum;
import top.infopub.mgr.common.page.ParamPage;
import top.infopub.mgr.common.vo.RspVo;
import top.infopub.mgr.flow.web.GenericFlowController;
import top.infopub.mgr.mkt.domain.RiskDomain;
import top.infopub.mgr.mkt.service.ProjectRiskService;
import top.infopub.mgr.mkt.vo.RiskVo;
import top.infopub.model.mkt.NormalNum;
import top.infopub.model.mkt.ProjectRisk;
import top.infopub.security.util.SessionUserUtils;
import top.infopub.security.vo.AuthorizationVO;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;
import java.util.Map;


/**
 *  项目风险控制器
 *
 * */

@Controller
@RequestMapping("/projectRisk")
public class ProjectRiskController extends GenericFlowController {

    @Autowired
   private ProjectRiskService projectRiskService;



    @RequestMapping("/toDealOrDetail")
    public String queryById(HttpServletRequest request, String proCode){
        request.setAttribute("proCode", proCode);
        return "mkt/lay-tenderPlanning-detail";
    }

    /**
     * 项目风险列表
     * @return
     */
    @RequestMapping("/queryDataByCondition")
    @ResponseBody
    public RspVo<RiskDomain> queryDataByCondition(RiskVo riskVo,
                                                  ParamPage paramPage) {
        Page<RiskDomain> page = new Page<RiskDomain>();
        page.setPageNum(paramPage.getPage());
        page.setPageSize(paramPage.getLimit());
        page = projectRiskService.selectPage(page, riskVo);
        System.out.println("page:"+page.getTotal());
        return RspVo.getSuccessResponse(page.getTotal(), page.getResult());
    }



    /**
     * 总数页面
     * @return
     */
    @RequestMapping("/selectByTotalNum")
    public String selectByTotalNum(HttpServletRequest request, NormalNum normalNum,String proCode){
        request.setAttribute("proCode", normalNum.getProCode());
        List<Map<String, String>> list = ProProcessDetailTypeEnum.asList();
        if (list != null && list.size() > 0) list.remove(0);
        request.setAttribute("proStage", list);
        System.out.println(normalNum.getProCode());
        return "mkt/lay-totalNum-list";
    }
    //    总数的方法
    @RequestMapping("/queryDataByTotalNum")
    @ResponseBody
    public RspVo<ProjectRisk> queryDataByTotalNum(NormalNum normalNum,ParamPage paramPage){
        Page<ProjectRisk> page = new Page<ProjectRisk>();
        page.setPageNum(paramPage.getPage());
        page.setPageSize(paramPage.getLimit());
        page = projectRiskService.selectByTotalNum(page,normalNum);
        return RspVo.getSuccessResponse(page.getTotal(),page.getResult());
    }



    /**
     * 未销项页面
     * @return
     */
    @RequestMapping("/selectByNormalNum")
    public String selectByNormalNum(HttpServletRequest request, NormalNum normalNum,String proCode){
        request.setAttribute("proCode", normalNum.getProCode());
        List<Map<String, String>> list = ProProcessDetailTypeEnum.asList();
        if (list != null && list.size() > 0) list.remove(0);
        request.setAttribute("proStage", list);
        System.out.println(normalNum.getProCode());
        return "mkt/lay-nomalNum-list";
    }

   /*未销项的方法*/
    @RequestMapping("/queryDataByNormalNum")
    @ResponseBody
    public RspVo<ProjectRisk> queryDataByNormalNum(NormalNum normalNum,ParamPage paramPage){
        Page<ProjectRisk> page = new Page<ProjectRisk>();
        page.setPageNum(paramPage.getPage());
        page.setPageSize(paramPage.getLimit());
        page = projectRiskService.selectByNormalNum(page,normalNum);
        return RspVo.getSuccessResponse(page.getTotal(),page.getResult());
    }



    /**
     * 高风险未销项页面
     * @return
     */
    @RequestMapping("/selectByHighRisk")
    public String selectByHighLevel(HttpServletRequest request, NormalNum normalNum,String proCode){
        request.setAttribute("proCode", normalNum.getProCode());
        List<Map<String, String>> list = ProProcessDetailTypeEnum.asList();
        if (list != null && list.size() > 0) list.remove(0);
        request.setAttribute("proStage", list);
        System.out.println(normalNum.getProCode());
        return "mkt/lay-highRisk-list";
    }
    @RequestMapping("/queryDataByHighRisk")
    @ResponseBody
    public RspVo<ProjectRisk> selectByHighLevel(NormalNum normalNum,ParamPage paramPage){
        Page<ProjectRisk> page = new Page<ProjectRisk>();
        page.setPageNum(paramPage.getPage());
        page.setPageSize(paramPage.getLimit());
        page = projectRiskService.selectByHighLevel(page,normalNum);
        return RspVo.getSuccessResponse(page.getTotal(),page.getResult());
    }




    /**
     * 中风险未销项页面
     * @return
     */
    @RequestMapping("/selectByMidRisk")
    public String selectByMidRisk(HttpServletRequest request, NormalNum normalNum,String proCode){
        request.setAttribute("proCode", normalNum.getProCode());
        List<Map<String, String>> list = ProProcessDetailTypeEnum.asList();
        if (list != null && list.size() > 0) list.remove(0);
        request.setAttribute("proStage", list);
        System.out.println(normalNum.getProCode());
        return "mkt/lay-midRisk-list";
    }
    @RequestMapping("/queryDataByMidRisk")
    @ResponseBody
    public RspVo<ProjectRisk> selectByMidLevel(NormalNum normalNum,ParamPage paramPage){
        Page<ProjectRisk> page = new Page<ProjectRisk>();
        page.setPageNum(paramPage.getPage());
        page.setPageSize(paramPage.getLimit());
        page = projectRiskService.selectByMidLevel(page,normalNum);
        return RspVo.getSuccessResponse(page.getTotal(),page.getResult());
    }


    /**
     * 低风险未销项页面
     * @return
     */
    @RequestMapping("/selectByLowRisk")
    public String selectByLowRisk(HttpServletRequest request, NormalNum normalNum,String proCode){
        request.setAttribute("proCode", normalNum.getProCode());
        List<Map<String, String>> list = ProProcessDetailTypeEnum.asList();
        if (list != null && list.size() > 0) list.remove(0);
        request.setAttribute("proStage", list);
        System.out.println(normalNum.getProCode());
        return "mkt/lay-lowRisk-list";
    }
    @RequestMapping("/queryDataByLowRisk")
    @ResponseBody
    public RspVo<ProjectRisk> selectByLowLevel(NormalNum normalNum,ParamPage paramPage){
        Page<ProjectRisk> page = new Page<ProjectRisk>();
        page.setPageNum(paramPage.getPage());
        page.setPageSize(paramPage.getLimit());
        page = projectRiskService.selectByLowLevel(page,normalNum);
        return RspVo.getSuccessResponse(page.getTotal(),page.getResult());
    }

    /**
     * 项目跟踪风险列表
     * **/
    @RequestMapping("/queryTrackRisk")
    @ResponseBody
    public RspVo queryTrackRisk(String proCode){
        List<ProjectRisk> risks = projectRiskService.selectByProCode(proCode);
        return RspVo.getSuccessResponse(risks);
    }

    /**
     * 项目跟踪风险销项
     * **/
    @RequestMapping("/editRiskById")
    @ResponseBody
    public RspVo editRiskById(String bodyStr){
        return   projectRiskService.updateByid(bodyStr);
    }
}
